package com.senseuni.da.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.senseuni.da.databinding.FragmentImageUsbTransferBinding
import com.senseuni.da.utils.AppUtils
import com.senseuni.da.utils.MmkvUtil

class ImageUSBTransferFragment : Fragment() {

    companion object {
        fun newInstance() = ImageUSBTransferFragment()
    }

    private lateinit var binding: FragmentImageUsbTransferBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentImageUsbTransferBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        val usbTransferSwitch = MmkvUtil.getInstance().getBoolean("usb_transfer_switch")
        binding.switchCompat.isChecked = usbTransferSwitch
        binding.switchCompat.setOnCheckedChangeListener { _, isChecked ->
            MmkvUtil.getInstance().put("usb_transfer_switch", isChecked)
            if (isChecked) {
                AppUtils.enableMtp(context)
            } else {
                AppUtils.disableMtp(context)
            }
        }
    }

}